classdef ziCurrInPort < MeasurementComponent.MachineUnit.IOPort.InputPort
    %ZICURRPORT �˴���ʾ�йش����ժҪ
    %   �˴���ʾ��ϸ˵��
    
    properties
    end
    
    methods
        function obj = ziCurrInPort(device)
            p=inputParser;
            p.addRequired('device', @(x) isa(x, 'EquipmentControl.ZI.ziMFLI'));
            p.parse(device);
            obj@MeasurementComponent.MachineUnit.IOPort.InputPort(device, 'CurrIn');
            obj.getCurrentSetting();
        end
    end
    %%
    methods
        function obj = setup(obj, varargin)
            zi = obj.device;
            obj.last_setting = obj.getCurrentSetting();
            
            p=inputParser;
            p.addParameter('isAC',    obj.last_setting.isAC,    @islogical);
            p.addParameter('is50Ohm', obj.last_setting.is50Ohm, @islogical);
            p.addParameter('isDiff',  obj.last_setting.isDiff,  @islogical);
            p.addParameter('isFloat', obj.last_setting.isFloat, @islogical);
            p.addParameter('range',   obj.last_setting.range, @(x) x > 0.0 && x <= 3.0);
            p.parse(varargin{:});
            
            
            if p.Results.isAC
                zi.enableSigInAC();
            else
                zi.disableSigInAC();
            end
            
            if  p.Results.is50Ohm
                zi.enableSigInImp50();
            else
                zi.disableSigInImp50();
            end
            
            if p.Results.isDiff
                zi.enableSigInDiff();
            else
                zi.disableSigInDiff();
            end
            
            if p.Results.isFloat
                zi.enableSigInFloat();
            else
                zi.disableSigInFloat();
            end
            zi.setRange(p.Results.range);
            
            obj.current_setting = obj.getCurrentSetting();
        end
        function setting = getCurrentSetting(obj)
            zi = obj.device;
            setting.isFloat = zi.getCurrInFloatStatus();
            setting.range = zi.getCurrInRange();
            setting.scaling = zi.getCurrInScaling();
            obj.current_setting = setting;
        end
        function obj = recoverLastSetting(obj)
            obj.setup(obj.last_setting);
        end        
        function obj = initialize(obj)
            obj.last_setting = obj.getCurrentSetting();
            obj.device.initializeSigIn();
            obj.current_setting = obj.getCurrentSetting();
        end
        
        %%
        function node = getScopeNode(~)
            node = ziScopeInput.CurrIn;
        end
    end
end

